package com.ambercrm.tools;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.Settings;

import com.yanzhenjie.permission.AndPermission;

import java.util.List;

public class PermissionUtils {
    public static void requestPermission(final Context context, final String[] permis, final OnPermissionGrand onPermissionGrand) {
        AndPermission.with(context)
                .runtime()
                .permission(permis)
                .onGranted(new com.yanzhenjie.permission.Action<List<String>>() {
                    @Override
                    public void onAction(List<String> data) {
                        if (permis.length == data.size() && onPermissionGrand != null) {
                            onPermissionGrand.permissionGrand();
                        }
                    }
                })
                .onDenied(new com.yanzhenjie.permission.Action<List<String>>() {
                    @Override
                    public void onAction(List<String> data) {
                        Intent intent = new Intent();
                        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                        intent.setData(Uri.fromParts("package", context.getPackageName(), null));
                        context.startActivity(intent);
                    }
                })
                .start();
    }
}
